package com.ctshk.rpc.starvip.dto.start_vip;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import java.io.Serializable;
import java.util.Objects;

/**
 * @BelongsProject: Test
 * @BelongsPackage: com.hef.test.StarRewards
 * @Author: hef
 * @CreateTime: 2021-04-09 16:13
 * @Description: 描述
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public abstract class SiebelMessage implements Serializable {
    @XmlAttribute(name = "MessageId")
    private String messageId;
    @XmlAttribute(name = "IntObjectName")
    private String intObjectName;
    @XmlAttribute(name = "InterfaceId")
    private String interfaceId;
    @XmlAttribute(name = "Operation")
    private String operation;
    @XmlAttribute(name = "MessageType")
    private String messageType;
    @XmlAttribute(name = "IntObjectFormat")
    private String intObjectFormat;
    @XmlElement(name = "ErrorInfo")
    private ErrorInfo errorInfo;

    /**
     * 	通过“每页查询数量”来限定分页查询每页显示的会员交易信息记录数量；
     */
    @XmlAttribute(name = "PageSize")
    private String pageSize;

    /**
     * 通过“是否为新查询”来区分板块（专业）公司提交的查询为新查询还是前一次查询的分页查询，即在原查询的查询结果里获取下一页查询结果数据；
     */
    @XmlAttribute(name = "NewQuery")
    private String newQuery;

    /**
     *  起始页
     */
    @XmlAttribute(name = "StartRowNum")
    private String startRowNum;

    /**
     * TxnNumber，表示当前查询结果返回的交易总数量，用于对接系统计算分页页数使用。
     */
    @XmlAttribute(name = "TxnNumber ")
    private String txnNumber ;

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @XmlRootElement(name = "ErrorInfo")
    public static class ErrorInfo {
        /**
         * 错误代码
         */
        @XmlElement(name = "ErrorCode")
        private Integer errorCode;
        /**
         * 错误信息
         */
        @XmlElement(name = "ErrorMessage")
        private String errorMessage;
        /**
         * 错误参数
         */
        @XmlElement(name = "ErrorParameter")
        private String errorParameter;

        @XmlTransient
        public Integer getErrorCode() {
            return errorCode;
        }

        @XmlTransient
        public String getErrorMessage() {
            return errorMessage;
        }

        @XmlTransient
        public String getErrorParameter() {
            return errorParameter;
        }
    }

    /**
     * 校验ErrorCode
     *
     * @param code
     * @return
     */
    public boolean checkErrorCode(int code) {
        return Objects.nonNull(errorInfo) && Integer.valueOf(code).equals(errorInfo.getErrorCode());
    }


    @XmlTransient
    public ErrorInfo getErrorInfo() {
        return errorInfo;
    }

    @XmlTransient
    public String getMessageId() {
        return messageId;
    }

    @XmlTransient
    public String getIntObjectName() {
        return intObjectName;
    }

    @XmlTransient
    public String getInterfaceId() {
        return interfaceId;
    }

    @XmlTransient
    public String getOperation() {
        return operation;
    }

    @XmlTransient
    public String getMessageType() {
        return messageType;
    }

    @XmlTransient
    public String getIntObjectFormat() {
        return intObjectFormat;
    }

    @XmlTransient
    public String getPageSize() {
        return pageSize;
    }

    @XmlTransient
    public String getNewQuery() {
        return newQuery;
    }

    @XmlTransient
    public String getStartRowNum() {
        return startRowNum;
    }

    @XmlTransient
    public String getTxnNumber() {
        return txnNumber;
    }
}
